home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Text / Digest-Browser-1.6 Folder / Views / CDisplayText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-29  |  2.8 KB  |  107 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.     CDisplayText.c
  3.     
  4.     Methods for a text editing pane.
  5.         
  6.     Copyright © 1989 Symantec Corporation. All rights reserved.
  7.     Copyright © 1991 Manuel A. Pérez.  All rights reserved.
  8.  
  9.     2/29/92 - Set Scroll Bars back to the top when a new item is shown
  10.  ******************************************************************************/
  11.  
  12.  
  13. #include "CDisplayText.h"
  14. #include "Browser.h"
  15.  
  16. void CDisplayText::IDisplayText(CView *anEnclosure, CBureaucrat *aSupervisor,
  17.         short vLoc, short heigth)
  18. {
  19. Rect    margin;
  20.  
  21. // JRB change from CEditText::IEditText to CBrowserEditText::IBrowserEditText
  22.     CBrowserEditText::IBrowserEditText(anEnclosure, aSupervisor,
  23.         1, height,                         // aWidth, aHeight
  24.         0, vLoc,                        // aHEncl, aVEncl
  25.         sizELASTIC, sizELASTIC,            // aHSizing, aVSizing
  26.         -1);                            // lineWidth
  27.     FitToEnclosure(TRUE, TRUE);            // fit horiz, but not vert
  28.  
  29.         /**
  30.          **    Give the edit pane a little margin.
  31.          **    Each element of the margin rectangle
  32.          **    specifies by how much to change that
  33.          **    edge. Positive values are down and to
  34.          **    right, negative values are up and to
  35.          **    the left.
  36.          **
  37.          **/
  38.  
  39.     SetRect(&margin, 2, 2, -2, -2);
  40.     ChangeSize(&margin, FALSE);
  41.     Specify(false, true, false);    // edit, select, style
  42.     SetCanBeGopher(true);
  43.  
  44.     // set default font and font size for this display
  45.     SetFontNumber(geneva);
  46.     SetFontSize(10);
  47.     (*macTE)->crOnly = 1;            // do wrap around
  48.  
  49.  
  50. }    /* IDisplayText */
  51.  
  52. void CDisplayText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  53. {
  54. }
  55.  
  56. /******************************************************************************
  57.  ProviderChanged
  58.  
  59.      Respond to the provider change.
  60.      
  61. ******************************************************************************/
  62.  
  63. void CDisplayText::ProviderChanged( CCollaborator *aProvider, long reason, void* info)
  64.  
  65. {
  66. BrowserItemPtr p;
  67. long line;
  68. long len;
  69. Handle text;
  70. long offset;
  71. LongPt aPosition;
  72.  
  73.     switch (reason) {
  74.         case textSelectionChanged:
  75.             p = (BrowserItemPtr) info;
  76.  
  77.             // get info from file and draw it on screen
  78.             if (p) {
  79.  
  80.                 //len = p->endAt - p->startAt;
  81.                 len = brGetEnd(p) - brGetStart(p);
  82.                 FailNIL(text = NewHandle(len));        // fail if no memory
  83.                 HLock(text);                        // lock handle
  84.                 //fseek(p->fp, p->startAt, 0);        // read in text
  85.                 //fread(*text, 1, len, p->fp);
  86.                 fseek(brGetFP(p), brGetStart(p), 0);        // read in text
  87.                 fread(*text, 1, len, brGetFP(p));
  88.  
  89.                 offset = 0;                            // replace '\n' with '\r'
  90.                 do {
  91.                     offset = Munger(text, offset, "\n", 1, "\r", 1);
  92.                 } while (offset > 0);
  93.  
  94.                 HUnlock(text);                        // unlock handle
  95.                 SetTextHandle(text);                // put text on window
  96.                 DisposHandle(text);                    // release handle 
  97.  
  98.                 // Set the scrollers back to the top
  99.                 aPosition.h = 0;
  100.                 aPosition.v = 0;
  101.                 ScrollTo(&aPosition, true);
  102.             }
  103.  
  104.             break;
  105.     }
  106. }    /* ProviderChanged */
  107.